package com.redis.threadlock;

public class LockDemo {
	private static Lock lock = new Lock();
	static int count = 0;
	
	public static void main(String[] args) {
		
	        new Thread(new Runnable() {
				@Override
				public void run() {
					lock.lock();
					try {
						Thread.sleep(5000);
					} catch (Exception e) {
						e.printStackTrace();
					}
			        LockDemo.count++;
			        lock.unlock();
					
				}
			},"A线程").start();
	        try {
				Thread.sleep(100);
			} catch (InterruptedException e1) {
				e1.printStackTrace();
			}
	        new Thread(new Runnable() {
				@Override
				public void run() {
					lock.lock();
					try {
						Thread.sleep(1000);
					} catch (Exception e) {
						e.printStackTrace();
					}
			        LockDemo.count++;
			        lock.unlock();
					
				}
			},"B线程").start();
	        new Thread(new Runnable() {
				@Override
				public void run() {
					lock.lock();
					try {
						Thread.sleep(1000);
					} catch (Exception e) {
						e.printStackTrace();
					}
			        LockDemo.count++;
			        lock.unlock();
					
				}
			},"C线程").start();
	        
	        new Thread(new Runnable() {
				@Override
				public void run() {
					lock.lock();
					try {
						Thread.sleep(1000);
					} catch (Exception e) {
						e.printStackTrace();
					}
			        LockDemo.count++;
			        lock.unlock();
					
				}
			},"D线程").start();
	}
	
	

}
